#include "choselevelwindow.h"

ChoseLevelWindow::ChoseLevelWindow(QWidget *parent) : QWidget(parent)
{
    resize(320,600);
    this->setWindowIcon(QIcon(":/coin/res/Coin0001.png"));
    this->setWindowTitle("翻金币");

    myPushButton* backBtn = new myPushButton(":/button/res/BackButton.png",":/button/res/BackButtonSelected.png");
    backBtn->setParent(this);
    backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());


    connect(backBtn,&myPushButton::clicked,[=](){
        emit this->backMainWIndow();
    });


    for(int i=0; i<20 ; i++)
    {
        myPushButton* choseBtn = new myPushButton(":/button/res/LevelIcon.png");
        choseBtn->setParent(this);
        choseBtn->move(25+i%4*70,170+i/4*70);

        QLabel* choseLabel = new QLabel(choseBtn);
        choseLabel->setFixedSize(choseBtn->width(),choseBtn->height());
        choseLabel->setText(QString::number(1+i));
        choseLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
        choseLabel->setAttribute(Qt::WA_TransparentForMouseEvents);

        connect(choseBtn,&myPushButton::clicked,[=](){
            game = new gameWindow(i+1);
            connect(game,&gameWindow::backChoseWindow,[=](){
                delete game;
                this->setGeometry(game->geometry());
                this->show();
            });
            this->hide();
            game->setGeometry(this->geometry());
            game->show();
        });
    }
}

void ChoseLevelWindow::paintEvent(QPaintEvent *)
{
    QPixmap pix;
    QPainter painter(this);
    pix.load(":/background/res/OtherSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/background/res/Title.png");
    painter.drawPixmap(0.5*(this->width()-pix.width()),this->height()*0.1,pix.width(),pix.height(),pix);
}

